package com.tys.algorithm.bak.code2;

public class Code07_Swap {

    public static void main(String[] args) {

        int a = 16;
        int b = 603;

        System.out.println(a);
        System.out.println(b);


        a = a ^ b;
        b = a ^ b;
        a = a ^ b;


        System.out.println(a);
        System.out.println(b);

        System.out.println("=====================");
        //注意数组中如果相同下标则会出错


        int[] arr = {3, 1, 100};

        int i = 0;
        int j = 0;

//        arr[i] = arr[i] ^ arr[j];
//        arr[j] = arr[i] ^ arr[j];
//        arr[i] = arr[i] ^ arr[j];
//        System.out.println(arr[i] + ", " + arr[j]);


        System.out.println(arr[0]);
        System.out.println(arr[2]);

        swap(arr, 0, 0);

        System.out.println(arr[0]);
        System.out.println(arr[2]);


    }


    public static void swap(int[] arr, int i, int j) {
        // arr[0] = arr[0] ^ arr[0];
        arr[i] = arr[i] ^ arr[j];
        arr[j] = arr[i] ^ arr[j];
        arr[i] = arr[i] ^ arr[j];
    }
}
